<template>
  <div>
    <div class="seach_box_container">
      <div class="left_go">
        <van-icon name="arrow-left" @click="onClickGo" />
      </div>
      <div class="input_box">
        <van-search
          v-model="value"
          placeholder="请输入搜索关键词"
          @keyup="onkeyup"
        />
      </div>
      <div class="right_seach">
        <span v-show="!show">取消</span>
        <span v-show="show" @click="onInput">搜索</span>
      </div>
    </div>
    <div>
      <div>
        <van-empty description="没有结果" v-show="show2" />
      </div>
      <div class="Recommended_box_container">
        <div class="Recommended_box" v-for="(item, index) in list" :key="index">
          <div class="title_box">
            <span>{{ item.course_classify_title }}</span>
          </div>
          <div class="content_box">
            <div class="top_box">
              <div class="font">{{ item.title }}</div>
              <div class="model">
                <div v-for="(item2, index) in item.course_label" :key="index">
                  <button class="title">{{ item2.label_name }}</button>
                </div>
              </div>
            </div>
            <div class="bottom">
              <div class="HeadPortrait">
                <div
                  v-for="(item2, index) in item.teacher"
                  :key="index"
                  v-show="index < 3"
                >
                  <img :src="item2.avatar" alt="" />
                  <p>{{ item2.teacher_name }}</p>
                </div>
              </div>
              <div class="buttom_title">
                <div>{{ item.sales_num }}人已报名</div>
                <div>免费</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 历史记录 -->
    <div class="history_box" v-show="show3">
      <div class="top_box">
        <div class="title_box"><h3>历史记录</h3></div>
        <div class="remove_box">
          <van-icon name="delete-o" @click="remove" />
        </div>
      </div>
      <div class="bottom_box">
        <span v-for="(item, index) in history" :key="index">{{ item }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { getTabLists } from "../../http/api";
export default {
  data() {
    return {
      value: "",
      show: false,
      id: this.$store.state.CategoryId,
      list: [],
      showlist: [],
      show2: false,
      show3: true,
      history: [],
    };
  },
  methods: {
    onClickGo() {
      this.$router.go(-1);
    },
    onkeyup() {
      this.show = true;
      this.show3 = false;
      if (this.value === "") {
        this.show = false;
        this.show2 = false;
        this.list = [];
        this.show3 = true;
      }
    },
    async onInput() {
      console.log(this.value);
      this.history.push(this.value);
      const res = await getTabLists(this.id);
      this.list = res.data.data;
      this.showlist = res.data.data;

      this.list = this.showlist.filter((item) => {
        return item.title.includes(this.value);
      });
      console.log(this.list);
      if (this.list.length === 0) {
        this.show2 = true;
      } else {
        return this.list;
      }
    },
    remove() {
      this.history = [];
    },
  },
};
</script>

<style lang="scss" scoped>
.seach_box_container {
  width: 100%;
  height: 50px;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  .left_go {
    width: 15%;
    height: 100%;
    // background-color: saddlebrown;
    display: flex;
    justify-content: center;
    align-items: center;
    .van-icon {
      font-size: 25px;
    }
  }
  .input_box {
    width: 70%;
    height: 100%;
    // background-color: seagreen;
  }
  .right_seach {
    width: 15%;
    height: 100%;
    // background-color: skyblue;
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    span {
      width: 50px;
      height: 30px;
      line-height: 30px;
      text-align: center;
    }
    span:nth-child(1) {
      background-color: #f4f4f4;
      color: #ccc;
    }
  }
}
.history_box {
  width: 100%;
  height: 1.5rem;
  background-color: #f4f4f4;
  margin-top: 20px;
  .top_box {
    width: 100%;
    height: 50%;
    // background-color: royalblue;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .title_box {
      font-size: 20px;
    }
    .remove_box {
      font-size: 15px;
    }
  }
  .bottom_box {
    width: 100%;
    height: 50%;
    // background-color: green;
    display: flex;
    align-items: center;
    span {
      padding: 3px;
      background-color: #ccc;
      border-radius: 20px;
      margin-left: 5px;
      font-size: 16px;
    }
  }
}
// 推荐好课
.Recommended_box_container {
  width: 100%;
  height: 100%;
  background-color: #fafafa;
  .Recommended_title {
    width: 95%;
    height: 1.5rem;
    // background-color: rebeccapurple;
    margin: 0 auto;
    font-size: 20px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
  .Recommended_box {
    width: 95%;
    height: 4rem;
    background-color: #fff;
    margin: 0 auto;
    border-radius: 20px;
    margin-top: 10px;
    .title_box {
      width: 75px;
      height: 25px;
      background-color: #ff8800;
      color: #fff;
      border-radius: 25px 9px 25px 9px;
      font-size: 12px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .content_box {
      width: 90%;
      height: 85%;
      //   background-color: springgreen;
      margin: 5px auto 0;
      .top_box {
        width: 100%;
        height: 50%;
        // background-color: steelblue;
        .font {
          width: 100%;
          height: 70%;
          font-size: 18px;
          //   background-color: rgb(207, 135, 235);
        }
        .model {
          width: 100%;
          height: 30%;
          display: flex;
          justify-content: flex-start;
          //   background-color: pink;
        }
        .model div {
          height: 100%;
          display: flex;
        }
        .title {
          //   width: 150px;
          height: 100%;
          font-size: 8px;
          border: none;
          outline: none;
          border-radius: 10px;
          margin-left: 5px;
          //   float: left;
        }
      }
      .bottom {
        width: 100%;
        height: 50%;
        // background-color: skyblue;
        .HeadPortrait {
          width: 100%;
          height: 50%;
          // background-color: darkblue;
          border-bottom: 1px solid #ccc;
          display: flex;
          justify-items: center;
          img {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            vertical-align: middle;
            float: left;
            margin-top: 10px;
            margin-left: 10px;
          }
          p {
            font-size: 16px;
            float: left;
            margin-top: 20px;
          }
        }
        .buttom_title {
          width: 100%;
          height: 50%;
          // background-color: slateblue;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
        .buttom_title div {
          font-size: 16px;
        }
        .buttom_title div:nth-child(2) {
          font-size: 18px;
          color: green;
        }
      }
    }
  }
}
</style>